// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   nseerdb.java

package include.nseerdb;

import java.io.*;
import java.sql.*;
import java.util.Properties;

public class nseerdb
{

	private String drivername;
	private String url;
	private String driverName;
	private String table;
	private String url1;
	private String url2;
	Connection conn;
	Statement stmt;
	Connection conn1;
	Statement stmt1;
	ResultSet rs;

	public nseerdb(String table)
	{
		conn = null;
		stmt = null;
		conn1 = null;
		stmt1 = null;
		rs = null;
		setProperty();
		this.table = table;
		url = (new StringBuilder(String.valueOf(url1))).append(table).append("?").append(url2).toString();
		driverName = drivername;
		try
		{
			Class.forName(driverName);
		}
		catch (ClassNotFoundException e)
		{
			System.err.println((new StringBuilder("nseerdb(String): ")).append(e.getMessage()).toString());
		}
	}

	public void setProperty()
	{
		Properties properties = new Properties();
		Properties properties1 = new Properties();
		try
		{
			InputStream inputstream = getClass().getClassLoader().getResourceAsStream("/conf/db.properties");
			InputStream inputstream1 = getClass().getClassLoader().getResourceAsStream("/conf/dbip.properties");
			properties.load(inputstream);
			properties1.load(inputstream1);
			if (inputstream != null)
				inputstream.close();
			inputstream1.close();
		}
		catch (IOException ex)
		{
			System.err.println("Open Propety File Error");
		}
		drivername = properties.getProperty("DRIVER");
		url1 = (new StringBuilder(String.valueOf(properties.getProperty("URL1")))).append(properties1.getProperty("IP")).append(":3306/").toString();
		url2 = properties.getProperty("URL2");
	}

	public String getTable()
	{
		return table;
	}

	public void setTable(String table)
	{
		this.table = table;
	}

	public ResultSet executeQuery(String sql)
		throws SQLException
	{
		conn = DriverManager.getConnection(url);
		stmt = conn.createStatement();
		rs = stmt.executeQuery(sql);
		return rs;
	}

	public boolean executeUpdate(String sql)
		throws SQLException
	{
		try
		{
			conn1 = DriverManager.getConnection(url);
			stmt1 = conn1.createStatement();
			stmt1.executeUpdate(sql);
		}
		catch (SQLException ex)
		{
			System.err.println((new StringBuilder("closeConn: ")).append(ex.getMessage()).toString());
			return false;
		}
		return true;
	}

	public boolean closeConn()
	{
		try
		{
			if (rs != null)
				rs.close();
			if (stmt != null)
				stmt.close();
			if (conn != null)
				conn.close();
			if (stmt1 != null)
				stmt1.close();
			if (conn1 != null)
				conn1.close();
		}
		catch (SQLException ex)
		{
			System.err.println((new StringBuilder("closeConn: ")).append(ex.getMessage()).toString());
			return false;
		}
		return true;
	}
}
